package com.example.dllo.my36kr.ui.activity.sonactivity;

import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;

import com.example.dllo.my36kr.R;
import com.example.dllo.my36kr.model.AcademyBean;
import com.example.dllo.my36kr.net.SingleVolley;
import com.example.dllo.my36kr.net.VolleyResult;
import com.example.dllo.my36kr.tools.NewsUrls;
import com.example.dllo.my36kr.ui.activity.AbsBaseActivity;
import com.example.dllo.my36kr.ui.adapter.AcademyAdapter;
import com.google.gson.Gson;

import java.util.List;


/**
 * 36氪研究院
 * Created by CPC_272 on 16/8/23.
 */
public class AcademyActivity extends AbsBaseActivity implements VolleyResult, View.OnClickListener, AdapterView.OnItemClickListener {
    private ListView academy_ls;
    private String academyUrl = NewsUrls.STUDY_URL;
    private List<AcademyBean.DataBean.DataBean1> dataBean1s;
    private ImageView academyBack;
    @Override
    protected int setLayout() {
        return R.layout.activity_academy;
    }

    @Override
    protected void initView() {
        academy_ls = byView(R.id.academy_ls);
        academyBack=byView(R.id.academy_back);
    }

    @Override
    protected void initData() {
       academyBack.setOnClickListener(this);
        academy_ls.setOnItemClickListener(this);
        SingleVolley.getInstence(getApplicationContext()).startRequest(academyUrl, this);
    }

    @Override
    public void success(String str, int type) {
    }
    @Override
    public void success(String str) {
        Gson gson = new Gson();
        AcademyBean dataBean = gson.fromJson(str,AcademyBean.class);
        AcademyBean.DataBean dataBean1 = dataBean.getData();
        dataBean1s = dataBean1.getData();
        AcademyAdapter academyAdapter = new AcademyAdapter(this);
        academyAdapter.setDatas(dataBean1s);
        academy_ls.setAdapter(academyAdapter);
    }
    @Override
    public void failure() {

    }

    @Override
    public void onClick(View v) {
        finish();
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        //当点击行布局时 跳转到NewsChildActivity 并将接口传递过去
        String intentUrl = NewsUrls.ChildUrl + dataBean1s.get(position).getFeedId();
        String title = dataBean1s.get(position).getTitle();
        Intent intent = new Intent(AcademyActivity.this, NewsChildActivity.class);
        intent.putExtra("url", intentUrl);
        intent.putExtra("title",title);
        startActivity(intent);
    }
}
